import javax.microedition.lcdui.Graphics;

public final class aj extends ba
{

    public ba a;
    public ba b;
    public k c;
    public be d;
    private static boolean e;

    private static ba a(ba ba1, int l, int i1)
    {
        if((ba1 instanceof m) || (ba1 instanceof ah))
            return ba1;
        else
            return new ah(bh.d(), ba1, l, i1);
    }

    public static aj a(ba ba1)
    {
        o o1 = bh.a("window.shell");
        ca ca1 = new ca(a(ba1, 0, 0));
        aj aj1;
        return aj1 = new aj(o1, ca1);
    }

    public static aj b(ba ba1)
    {
        o o1 = bh.a("form.shell");
        aj aj1;
        (aj1 = new aj(o1, a(ba1, -100, -100))).L |= 4;
        return aj1;
    }

    private aj(o o1)
    {
        super(o1);
        d(-100, -100);
        d = new be(this);
    }

    public aj(o o1, ba ba1)
    {
        this(o1);
        a(0, ba1);
    }

    public final ah b()
    {
        return (ah)a(a, true);
    }

    private ba a(ba ba1, boolean flag)
    {
        if(flag)
        {
            if(ba1 instanceof ah)
                return ba1;
        } else
        if(ba1 instanceof ap)
            return ba1;
        if(ba1 != null)
        {
            for(int l = 0; l < ba1.g_(); l++)
            {
                ba ba2;
                if((ba2 = a(ba1.a(l), flag)) != null)
                    return ba2;
            }

        }
        return null;
    }

    public final boolean a(int ai[])
    {
        ah ah1 = null;
        if(b != null)
            ah1 = b.b();
        if(ah1 == null)
            ah1 = b();
        if(ah1 != null)
            return ah1.a(ai);
        else
            return a(0).a(ai);
    }

    public final int g_()
    {
        return 2;
    }

    public final ba a(int l)
    {
        if(l == 0)
            return a;
        else
            return d;
    }

    public final void a(int l, ba ba1)
    {
        if(l == 0)
        {
            if(ba1 != null)
                ba1.H = this;
            a = ba1;
        }
    }

    public final void d()
    {
        d.d();
    }

    public final boolean h()
    {
        return (super.L & 4) != 0;
    }

    public final boolean i()
    {
        return (super.L & 0x20) != 0;
    }

    public final void b(int l)
    {
        ba ba1;
        ah ah1;
        if((ba1 = b) != null && (ah1 = ba1.b()) != null)
        {
            bk bk1;
            short word0;
            int i1 = (word0 = (bk1 = ba1.K).d) + bk1.f;
            short word1;
            int j1 = (word1 = bk1.e) + ba1.y();
            ah1.a(l, word1, i1, j1, word0);
        }
    }

    public final void a(ba ba1, int l)
    {
        ba ba2 = b;
        b = ba1;
        if(ba2 != null)
            ba2.A();
        if(ba1 != null)
        {
            ba1.A();
            if(ba1 != ba2)
                bh.b().a(ba1, -2);
            bh.b().a(this, l);
        }
    }

    public final boolean c(ba ba1)
    {
        for(; ba1 != null; ba1 = ba1.H)
            if(ba1.F())
                return ba1 == b;

        return false;
    }

    public static ba a(boolean flag, ba ba1)
    {
        e = false;
        ba ba2 = ba1;
        boolean flag1 = false;
        if(ba1.g_() > 0 && ba1.F())
            flag1 = true;
        while(ba1 != null) 
        {
            ba ba3 = ba1.H;
            if(!flag1 && ba1.g_() > 0)
            {
                if((ba1 = flag ? ba1.r() : ba1.s()) == null)
                    ba1 = ba3;
            } else
            {
                if(ba3 == null)
                    return null;
                if((ba1 = flag ? ba3.e(ba1) : ba3.f(ba1)) == null)
                {
                    ba1 = ba3;
                    flag1 = true;
                } else
                {
                    flag1 = false;
                }
            }
            if(ba1 instanceof ah)
                e = true;
            if(ba1.F())
                return ba1;
            if(ba1 == ba2)
                return null;
        }
        return null;
    }

    private static boolean g(ba ba1)
    {
        ah ah1;
        if(ba1 != null)
        {
            if((ah1 = ba1.b()) != null)
                return ah1.a(ba1.K);
            else
                return true;
        } else
        {
            return false;
        }
    }

    private boolean c(int l)
    {
        boolean flag = l == 5 || l == 6;
        ba ba1;
        ba ba2;
        if((ba1 = b) == null)
        {
            if(g(ba2 = a(flag, a)))
            {
                a(ba2, flag ? 2 : 5);
                return true;
            }
        } else
        {
            boolean flag1 = false;
            bk bk1 = ba1.K;
            ba ba3 = ba1;
            ba ba4 = null;
            while((ba3 = a(flag, ba3)) != null) 
            {
                if(ba4 == null)
                    ba4 = ba3;
                if(e)
                {
                    a(ba3, l);
                    return true;
                }
                if(bk.a(l, bk1, ba3.K))
                    if(!g(ba3))
                    {
                        return false;
                    } else
                    {
                        a(ba3, l);
                        return true;
                    }
            }
            if(ba4 != null)
            {
                a(ba4, l);
                return true;
            }
        }
        return false;
    }

    public final int a(int l, int i1, int j1, int k1)
    {
        super.L |= 0x400;
        try{
        if(c instanceof cd)
            ((cd)c).h();
        be be1 = d;
        if ((be1).C()) {
            int l1;
        if(!ce.a(11)){

        l1 = be1.j(0);
        if(a != null)
            a.b(l, i1, j1, k1 - l1);
        be1.b(l,(i1 + k1) - l1,j1,l1);
        }else{
        l1 = j1 / 7;
        if(ce.a(28))
        {
            l1 = j1 / 5;
            if(ce.a(29))
                l1 = j1 / 6;
        }
        if(a != null)
            a.b(l, i1, j1 - l1, k1);
        be1.b((l + j1) - l1,i1,l1,k1);
        }
        }else
        if(a != null) {
            a.b(l, i1, j1, k1);
        }
        if(a != null && b == null)
            b = a(true, a);
        d.d();
        super.L &= 0xfffffbff;
        }catch(Exception exception){
        super.L &= 0xfffffbff;
        }
        return k1;
    }

    public final void a(Graphics g1, bh bh1, o o1, int l, int i1)
    {
        int j1 = g1.getTranslateX();
        int k1 = g1.getTranslateY();
        if(a != null)
            bh.a(g1, bh1, a);
        be be1;
        if((be1 = d).C())
        {
            int l1 = super.K.d + o1.c();
            int i2 = super.K.e + o1.e();
            g1.translate(((((ba) (be1)).K.d - l1) + j1) - g1.getTranslateX(), ((((ba) (be1)).K.e - i2) + k1) - g1.getTranslateY());
            bh.a(g1, bh1, d);
        }
    }

    public final boolean a(int l, int i1) {
        if (c instanceof cd)
            return c.a(l, i1);
        if ((b instanceof j) && l == 1 && (i1 == -6 || i1 == -5 || i1 == 10))
            return b.a(l, i1);
        if (l == 1 && (i1 == -6 || i1 == -7 || i1 == -5) && d.b(i1))
            return true;
        if (b != null && b.a(l, i1))
            return true;
        if (c != null && c.a(l, i1))
            return true;
        if (l != 2) {
            byte byte0 = 0;
            switch (i1) {
                case -4:
                case 54:
                    byte0 = 5;
                    break;
                case -3:
                case 52:
                    byte0 = 2;
                    break;
                case -2:
                case 56:
                    byte0 = 6;
                    break;
                case -1:
                case 50:
                    byte0 = 1;
                    break;
            }
            if (byte0 != 0) {
                if (c(byte0))
                    return true;
                ah ah1;
                if ((ah1 = b()) != null && ah1.e(byte0))
                    return true;
            }
        }
        return false;
    }

    public final boolean a(int l, int i1, int j1)
    {
        if(!super.a(l, i1, j1) && l == 1 && (c instanceof cd))
            ((cd)c).a(true);
        return true;
    }
}